﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using Br.Client.Core.Entity;

namespace Br.Client.Ui
{
    public partial class LoginForm : Form
    {
        public LoginForm()
        {
            InitializeComponent();
        }
        JavaScriptSerializer json = new JavaScriptSerializer();
        private void LoginForm_Load(object sender, EventArgs e)
        {

        }

        private void btnAccept_Click(object sender, EventArgs e)
        {
            try
            {
                // var form = new MainForm();
                //return;
                var info = new LoginInfo { IsConnected = true, NowConnectedNum = 4, WaitingPeopNum = 1, Remark = "连接成功" };
                var sendStr = json.Serialize(new { obj1 = info, obj2 = new TestInfo { a=334223,b="m阿哥啫嗨！"} });
                var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                socket.Connect(txtIp.Text, int.Parse(txtPort.Text));
                socket.Send(Encoding.UTF8.GetBytes(sendStr));
                var reBuf = new byte[1024];
                int n = socket.Receive(reBuf);
                var getStr = Encoding.UTF8.GetString(reBuf, 0, n);
                MessageBox.Show(getStr);
                //var deObj = json.Deserialize<LoginInfo>(getStr);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }

    public class TestInfo
    {
        public int a { get; set; }
        public string b { get; set; }
    }
}
